/*
 * Copyright (c) 2025 EasyAdmin
 * All rights reserved.
 *
 * This file is part of the [EasAdmin] project.
 * Unauthorized copying of this file, via any medium, is strictly prohibited.
 * Proprietary and confidential.
 *
 * Author: EasyAdmin ( 1073602@qq.com )
 * Website: https://www.xhxiao.com
 */
package com.easy.module.system.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.easy.framework.common.validate.Add;
import com.easy.framework.common.validate.RegexValidator;
import com.easy.framework.common.validate.Update;
import com.easy.framework.common.xss.Xss;
import com.easy.framework.database.entity.LogicDeleteEntity;

import com.easy.framework.poi.annotation.Excel;
import com.easy.framework.poi.annotation.Export;
import com.easy.framework.poi.annotation.Import;
import com.easy.framework.poi.annotation.Option;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.*;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.List;

/**
 * 用户表 实体
 *
 * @author EasyAdmin ( 1073602@qq.com )
 * @date 2025-08-19 14:02:10
 */
@Getter
@Setter
@TableName("sys_user")
public class SysUser extends LogicDeleteEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 用户编号
     */
    @Excel(name = "用户编号")
    @NotNull(message = "用户编号不能为空", groups = {Update.class})
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 用户名
     */
    @Excel(name = "用户名")
    @Xss(message = "用户名不能包含脚本字符")
    @NotBlank(message = "用户名不能为空", groups = {Add.class, Update.class})
    @Size(message = "用户名长度不能超过30个字符", min = 0, max = 32, groups = {Add.class, Update.class})
    private String username;

    /**
     * 昵称
     */
    @Excel(name = "昵称")
    @NotBlank(message = "昵称不能为空", groups = {Add.class, Update.class})
    @Size(message = "昵称长度不能超过50个字符", min = 0, max = 50, groups = {Add.class, Update.class})
    private String nickname;

    /**
     * 用户类型
     */
    @Excel(name = "用户类型", dictType = "sys_user_type")
    private Integer type;

    /**
     * 邮箱
     */
    @Excel(name = "邮箱")
    @Email(message = "邮箱格式不正确")
    @Size(message = "邮箱长度必须小于50个字符", max = 64, groups = {Add.class, Update.class})
    private String email;

    /**
     * 手机号码
     */
    @Excel(name = "手机号码")
    @Size(message = "手机号码长度不能超过11个字符", max = 11, groups = {Add.class, Update.class})
    private String mobile;

    /**
     * 性别（0未知 1男 2女）
     */
    @Excel(
            name = "性别",
            options = {
                    @Option(value = "0", name = "未知"),
                    @Option(value = "1", name = "男"),
                    @Option(value = "2", name = "女")
            }
    )
    private Integer sex;

    /**
     * 头像地址
     */
    @Size(message = "头像长度必须小于255个字符", max = 255, groups = {Add.class, Update.class})
    private String avatar;

    /**
     * 密码
     */
    @JsonIgnore
    private String password;

    /**
     * 电子签名
     */
    @Size(message = "电子签名长度必须小于255个字符", max = 255, groups = {Add.class, Update.class})
    private String autograph;

    /**
     * 状态（0正常 1停用）
     */
    @Excel(
            name = "帐号状态",
            options = {
                    @Option(value = "0", name = "正常"),
                    @Option(value = "1", name = "停用")
            }
    )
    private Integer status;

    /**
     * 最后登录IP
     */
    @Excel(name = "最后登录IP", importable = @Import(enabled = false))
    private String loginIp;

    /**
     * 最后登录时间
     */
    @Excel(name = "最后登录时间", export = @Export(width = 30, format = "yyyy-MM-dd HH:mm:ss"), importable = @Import(enabled = false))
    private Date loginAt;


    /**
     * 部门ID
     */
    @TableField(exist = false)
    private Long deptId;

    /**
     * 角色对象
     */
    @TableField(exist = false)
    private List<SysRole> roles;

    /**
     * 用户角色编号集合
     */
    @TableField(exist = false)
    private List<Long> roleIds;

    /**
     * 岗位组
     */
    @TableField(exist = false)
    private List<Long> postIds;
}
